# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=opus
pkgver=1.5.2
pkgrel=0
pkgdesc="Codec designed for interactive speech and audio transmission over the Internet"
url="https://www.opus-codec.org/"
arch="all"
license="BSD-3-Clause"
makedepends="meson"
subpackages="$pkgname-dev $pkgname-doc"
source="https://downloads.xiph.org/releases/opus/opus-$pkgver.tar.gz
	arm32.patch
	fix-test.patch
	"

case "$CARCH" in
arm*)
	# the tests pass, but with contention armhf is really slow, and they can take
	# over 20 minutes on one test
	options="$options !check"
	;;
esac

# secfixes:
#   0:
#     - CVE-2022-25345

build() {
	CFLAGS="${CFLAGS/-Os/-O2}" \
	CPPFLAGS="${CPPFLAGS/-Os/-O2}" \
	abuild-meson \
		-Db_lto=true \
		-Dcustom-modes=true \
		-Dtests="$(want_check && echo enabled || echo disabled)" \
		. output
	meson compile -C output
}

check() {
		meson test -t10 --no-rebuild --print-errorlogs -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output
	install -Dm644 COPYING "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}

sha512sums="
78d963cd56d5504611f111e2b3606e236189a3585d65fae1ecdbec9bf4545632b1956f11824328279a2d1ea2ecf441ebc11e455fb598d20a458df15185e95da4  opus-1.5.2.tar.gz
4218a3bc31efb91aa6b9cb2ac5928e63c34fd3b5aac61c68fa13b5a5fee00f902a1a03c61735d0610b0ded8f5b5e789494ea24165383bd4501d6a16e422e8eb6  arm32.patch
093650e1593c6d653a7037f199ea04f37e75c5783777112d26df9d689a548211a706ab6964b67edfe0818a0d02de2cebf734e222432bdbc13a91cb15a97e47a3  fix-test.patch
"
